<template>
	<view class="content">
		<view class="top-img">
			<image src="../../../static/img/jfsc.png" mode="aspectFill"></image>
		</view>
		<view class="list">
			<custom-waterfalls-flow :value="list" @wapperClick="wapperClick" @imageClick="wapperClick">
				<!-- #ifdef H5 -->
				<template v-slot:default="item">
					<view class="item">
						<view class="title">{{item.name}}</view>
						<view class="bottom">
							<view>
								鸭鸭卡<text>{{item.source}}</text>
							</view>
							<view>兑换</view>
						</view>
					</view>
				</template>
				<!-- #endif -->
				<!-- #ifdef MP-WEIXIN -->
				<view class="item" v-for="(item,index) in list" @click="wapperClick(item)" :key="index"
					slot="slot{{index}}">
					<view class="title">{{item.name}}</view>
					<view class="bottom">
						<view>
							鸭鸭卡<text>{{item.source}}</text>
						</view>
						<view>兑换</view>
					</view>
				</view>
				<!-- #endif -->
			</custom-waterfalls-flow>
		</view>
	</view>
</template>

<script>
	import {
		getAction
	} from '../../../common/request'
	export default {
		data() {
			return {
				list: [{
						image: 'https://via.placeholder.com/200x300.png/ff0000',
						title: '我是标题1',
						desc: '描述描述描述描述描述描述描述描述1'
					},
					{
						image: 'https://via.placeholder.com/200x200.png/2878ff',
						title: '我是标题2',
						desc: '描述描述描述描述描述描述描述描述2'
					},
					{
						image: 'https://via.placeholder.com/200x300.png/ff0000',
						title: '我是标题1',
						desc: '描述描述描述描述描述描述描述描述1'
					},
					{
						image: 'https://via.placeholder.com/200x200.png/2878ff',
						title: '我是标题2',
						desc: '描述描述描述描述描述描述描述描述2'
					},
					{
						image: 'https://via.placeholder.com/200x300.png/ff0000',
						title: '我是标题1',
						desc: '描述描述描述描述描述描述描述描述1'
					},
					{
						image: 'https://via.placeholder.com/200x200.png/2878ff',
						title: '我是标题2',
						desc: '描述描述描述描述描述描述描述描述2'
					}
				],
				current: 1,
				finash: false
			}
		},
		onLoad() {
			this.reload()
		},
		onReachBottom() {
			this.current++
			this.getList()
		},
		methods: {
			wapperClick(e) {
				uni.navigateTo({
					url: "/pages/car/detail/detail?id=" + e.id
				})
			},
			reload() {
				this.current = 1
				this.list = []
				this.finash = false
				this.getList()
			},
			getList() {
				if (this.finash) return
				uni.showLoading({
					mask: true
				})
				getAction('/goods', {
					page: this.current,
					pageSize: 10
				}).then(res => {
					uni.hideLoading()
					res.data.data = res.data.data.map(i => {
						return {
							...i,
							image: i.pic && i.pic[0]
						}
					})
					this.list = this.list.concat(res.data.data)
					this.finash = res.data.last_page == res.data.current_page
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {

		.top-img {
			image {
				width: 100%;
				height: 304rpx;
			}
		}

		.list {

			padding: 0 30rpx;
		}

		.item {
			background: rgba(245, 245, 245, 1);
			padding: 20rpx;

			.title {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFangSC-Regular;
				font-weight: 400;
				color: #2B2B2B;
				line-height: 36rpx;
				margin-bottom: 30rpx;
			}

			.bottom {
				display: flex;
				align-items: center;
				justify-content: space-between;

				>view:nth-of-type(1) {
					font-size: 18rpx;

					text {
						font-size: 36rpx
					}
				}

				>view:nth-of-type(2) {
					width: 102rpx;
					height: 52rpx;
					background: #FF5035;
					box-shadow: 0rpx 0 20rpx 0rpx #E4E4E4;
					opacity: 1;
					font-size: 26rpx;
					color: #FFFFFF;
					line-height: 52rpx;
					text-align: center;
					border-radius: 10rpx;
				}
			}
		}
	}
</style>